package tedu.study.day04;

import java.util.Scanner;

public class ScoreLevel {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);//新建一个扫描仪
        System.out.println("请输入成绩（以回车结束）");
        double score = scan.nextDouble();//扫描小数，并赋值给score
        System.out.println("成绩为："+score);


        //判断成绩等级,(666,-42,99,78,66,20)
        //条件最全，但部分代码无意义
        /*
        if(score>=90){
            System.out.println("成绩为"+score+",A-优秀");
        }else if(score>=80 && score<90){
            System.out.println("成绩为"+score+",B-良好");
        }else if(score>=60 && score<80){
            System.out.println("成绩为"+score+",C-中等");
        }else if(score<60){
            System.out.println("成绩为"+score+",D-不合格");
        }

        //代码优化
        if(score>=90){
            System.out.println("成绩为"+score+",A-优秀");
        }else if(score>=80){
            System.out.println("成绩为"+score+",B-良好");
        }else if(score>=60){
            System.out.println("成绩为"+score+",C-中等");
        }else{
            System.out.println("成绩为"+score+",D-不合格");
        }



        //添加成绩合法化判断
        if(score>=0 && score<=100){
            System.out.println("成绩合法");
            if(score>=90){
                System.out.println("成绩为"+score+",A-优秀");
            }else if(score>=80){
                System.out.println("成绩为"+score+",B-良好");
            }else if(score>=60){
                System.out.println("成绩为"+score+",C-中等");
            }else{
                System.out.println("成绩为"+score+",D-不合格");
            }
        }else{
            System.out.println("成绩不合法");
        }
        */

        //优化嵌套,减少嵌套层数
        if(score<0 || score>100){
            System.out.println("成绩不合法");
        }else if(score>=90){
            System.out.println("成绩为"+score+",A-优秀");
        }else if(score>=80){
            System.out.println("成绩为"+score+",B-良好");
        }else if(score>=60){
            System.out.println("成绩为"+score+",C-中等");
        }else{
            System.out.println("成绩为"+score+",D-不合格");
        }


    }

}
